import React from 'react';

export const useMetaTag = (condition: boolean, content: string) => {
  React.useEffect(() => {
    if (!condition) {
      return;
    }
    const metaTag = document.createElement('meta');
    metaTag.name = 'theme-color';
    metaTag.content = content;
    document.getElementsByTagName('head')[0].appendChild(metaTag);

    return () => {
      if (!condition) {
        return;
      }
      const metaTag = document.querySelector('meta[name="theme-color"]');
      if (metaTag) {
        metaTag.parentNode?.removeChild(metaTag);
      }
    };
  }, [condition, content]);
};
